{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6c47a19b-301e-42b4-ac8c-2eeef19abdbf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['gpt-3.5-turbo', 'gpt-4']\n",
      "['glm-4', 'glm-3-turbo']\n",
      "['qwen-turbo', 'qwen-plus']\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "import yaml\n",
    "\n",
    "class SupportedModels:\n",
    "    def __init__(self):\n",
    "        self._models = None\n",
    "\n",
    "    def initialize(self, models_file):\n",
    "        with open(models_file, \"r\") as f:\n",
    "            models = yaml.safe_load(f)\n",
    "\n",
    "        self._models = models\n",
    "\n",
    "    def get(self, provider):\n",
    "        if self._models and provider in self._models:\n",
    "            return self._models[provider]\n",
    "        return []\n",
    "\n",
    "# 使用示例\n",
    "# 创建一个SupportedModels的实例\n",
    "supported_models = SupportedModels()\n",
    "\n",
    "# 初始化SupportedModels实例\n",
    "supported_models.initialize(\"models.yaml\")\n",
    "\n",
    "# 获取特定提供商支持的模型列表\n",
    "print(supported_models.get(\"OpenAI\"))   # 输出：['gpt-3.5-turbo']\n",
    "print(supported_models.get(\"ZhipuAI\"))  # 输出：['glm-4', 'glm-3-turbo']\n",
    "print(supported_models.get(\"Tongyi\"))   # 输出：['qwen-turbo', 'qwen-plus']\n",
    "print(supported_models.get(\"ABC\"))      # 输出：[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "478d3f56-5598-4357-b753-4bea263f6fb7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
